package com.jimmy.tx.service.impl;

import com.jimmy.tx.dao.LogDao;
import com.jimmy.tx.dao.UserDao;
import com.jimmy.tx.service.LogService;
import com.jimmy.tx.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.support.TransactionCallback;
import org.springframework.transaction.support.TransactionCallbackWithoutResult;
import org.springframework.transaction.support.TransactionTemplate;

/**
 * @version 1.0
 * @ ClassName UserServiceImpl
 * <p> noRollbackFor = ArithmeticException.class,noRollbackForClassName = "ArithmeticException" 意义一样只要配置一个就行指定不回滚
 * @ author JIMMY
 * @ Date 2020/11/5 0005 下午 8:40
 */
@Service("userService")
//@Transactional(timeout = -1,propagation = Propagation.REQUIRED,isolation = Isolation.DEFAULT,readOnly = false,rollbackFor = RuntimeException.class)
public class UserServiceImpl implements UserService {
    @Autowired
    private UserDao userDao;
    @Autowired
    private LogService logService;


    /**
     * @param from
     * @param to
     * @param money
     */
    @Transactional(propagation = Propagation.REQUIRED)
    public void transfer(String from, String to, Double money) {
        userDao.outMoney(from,money);
        userDao.inMoney(to,money);
        int i = 1/0;   //放这还是没法记日志
        logService.insertLog(2,"haha log");
//        int i = 1/0; //放这才能记日志唉
    }

}
